<?php

use think\Config;

if (!function_exists('save_json_file')) {

    /**
     * @param $name 文件名
     * @param $data 保存数据
     * @return void
     */
    function save_json_file($name, $data)
    {
        $dataPath = Config::get('path_json_data');
        if (!is_dir($dataPath)) {
            mkdir($dataPath, 0777, true);
        }
        $saveData = json_encode($data, true);
        file_put_contents($dataPath . $name, $saveData);
    }

}
    function save_json_by_type($type,$data){
        $name = Config::get($type.'_file');
        save_json_file($name,$data);
        return ;
        switch ($type)
        {
            case "warehouse":
                save_json_file($name,$data);
                break;
            case "shelves":
                save_json_file($name,$data);
                break;
            case "procure":
                /* save_json_file($name,$data['poorder']);
                $item_name =  Config::get('procure_item_file');
                save_json_file($item_name,$data['item']); */
                save_json_file($name,$data);
                break;
            case "inventory":
                save_json_file($name,$data);
                break;
            case "kc":
                save_json_file($name,$data);
                break;
            case "kcmx":
                save_json_file($name,$data);
                break;
            case "appmaterial":
                /*save_json_file($name,$data['poorder']);
                $item_name =  Config::get('material_item_file');*/
                save_json_file($name,$data);
                break;
            default:
                save_json_file($name,$data);
                echo "";
        }
    }
    
    /*
     * 获得pda标识
     *   */
    function getPdaFlag($uuid = ''){
        $pda_flag_arr = config('site.pda_flag');//设备类型数组
        $pda_flag = '';//设备标识
        if($pda_flag_arr){
            $pda_flag_arr = array_flip($pda_flag_arr);
            if(isset($uuid)&&isset($pda_flag_arr[$uuid])){
                $pda_flag = $pda_flag_arr[$uuid];
            }
        }
        return $pda_flag;
    }

